package com.xinqi.modules.chat.chat.group.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.chat.chat.group.client.RemoteChatClient;
import com.xinqi.modules.chat.chat.group.dto.req.ChatClassUserGroupCreateDTO;
import com.xinqi.modules.chat.chat.group.dto.rsp.ChatGroupResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 聊天模块服务 -- 熔断降级处理
 *
 * @Author：yyzhen
 * @Package：com.xinqi.modules.chat.chat.group.factory
 * @Project：xinqi.modules-cloud-plus
 * @name：RemoteChatFallbackFactory
 * @Date：2023/3/10 15:31
 * @Filename：RemoteChatFallbackFactory
 */
@Slf4j
@Component
public class RemoteChatFallbackFactory implements FallbackFactory<RemoteChatClient> {
    @Override
    public RemoteChatClient create(Throwable throwable) {
        log.error("聊天服务调用失败:{}", throwable.getMessage());
        return new RemoteChatClient() {

            @Override
            public R<Boolean> accountCancel(Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<ChatGroupResultDTO> classCreateGroup(ChatClassUserGroupCreateDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> classDisbandGroup(Long classId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> classShiftGroup(Long classId, Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> classExitGroup(Long classId, Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<Boolean> classJoinGroup(Long classId, Long userId) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
